<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>"> 
    <title>添加挂号界面</title>  
    <link rel="stylesheet" href="<%=path %>/plugins/layui/css/layui.css" media="all">
  </head>

  <script src="<%=path %>/plugins/layui/layui.js"></script>
  
  <body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>填写标准费用界面</legend>
</fieldset>
<form class="layui-form layui-form-pane" id="StandardForm" lay-filter="example" action="">
  <div class="layui-form-item">
    <label class="layui-form-label" style="width:200px;">治疗标准名称</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text" name="standName"  placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" style="width:200px;">费用价格</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text" name="standPrice"  placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="standPrice">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label" style="width:200px;">标准单位</label>
    <div class="layui-input-block layui-input-inline" style="margin-left: 0px; width: 500px">
      <select name="standUnit" lay-filter="standUnit" lay-verify="required">
        <option value=""></option>
        <option value="次" selected="">次</option>
        <option value="天" >天</option>
      </select>
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label" style="width:200px;">治疗标准描述</label>
    <div class="layui-input-inline">
      <textarea style="width:500px;" name="standDesc" id="standDesc" placeholder="请输入" class="layui-textarea" lay-verify="required"></textarea>
    </div>
  </div>
  <div class="layui-form-item" align="center">
    <button class="layui-btn" lay-submit="" lay-filter="submit">保存信息</button>
  </div>
  </form>
</body>
  
<script>
layui.use(['form', 'layedit', 'laydate', 'jquery'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,$ = layui.jquery;

    laydate.render({
    elem: '#test1'
    });
  
 //自定义验证规则
    form.verify({
     standPrice: [/^(0|([1-9]\d{0,9}(\.\d{1,2})?))$/, '请输入正确的价格格式！']
  }); 
  
  //监听提交
  form.on('submit(submit)', function(data){
 	$.ajax({
  		url: '<%=path%>/biz/Standard_checkStandName.action',
  		type: 'GET',
  		data: {'standName':data.field.standName},
  		dataType: 'json',
  		success: function(data){ 
  			var json = eval("("+data+")");//将数据转换成json类
  			console.log(json.isSucceed);
  			//品名称不存在
			if(!json.isSucceed){
				$.ajax({
					url: '<%=path%>/biz/Standard_add.action',
					type: 'POST',
					data: $('#StandardForm').serialize(),
					dataType: 'json',
					success: function(data){
						var json = eval("("+data+")");
						//添加成功
						if(json.isSucceed){
							message("添加成功~");
							//返回挂号列表
							location.href = "<%=path%>/biz/Standard_standardList.action";
						}else{
							message("添加失败~不解释");
							//关闭当前iframe弹出层
							parent.layer.close();
						}
					},
					error: function(data){
						layer.msg("请求失败");
					}
				});
			}
			//学号已存在
			if(json.isSucceed){
					message("此标准费用已经存在了喔");
				}
  			},
  		error: function(data){
  			layer.msg("请求失败");
  		}
  	});
    return false;//阻止表单跳转
  }); 
  
  
  //信息提示弹出层
  function message(data){
      layer.open({
        content: '<div style="padding: 20px 100px;">'+ data +'</div>'
        ,btn: '朕知道啦'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
        ,yes: function(){
          layer.closeAll();
        }
      }); 
  }

  
  $('#layerDemo .layui-btn').on('click', function(){
    var othis = $(this), method = othis.data('method');
    active[method] ? active[method].call(this, othis) : '';
  });
  
});
</script>
